package com.qch.rabbitmq.demo;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @Author qch
 * @Date 2021/5/17
 */
public class MyProducer {
    public static void main(String[] args) throws Exception{
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setUri("amqp://root:123456@192.168.142.135:5672/%2f");
        Connection connection = connectionFactory.newConnection();
        final Channel channel = connection.createChannel();
        channel.queueDeclare("queue.ca", false, false, false, null);
        channel.exchangeDeclare("ex.ca", "direct",false, false, false, null);
        channel.queueBind("queue.ca", "ex.ca", "key.ca");
        for (int i = 0; i <5 ; i++) {
            channel.basicPublish("ex.ca","key.ca",null,("hello"+i).getBytes());
        }
        channel.close();
        connection.close();
    }
}
